package main

import (
	"fmt"
	"time"
)

type Person struct {
	name string
}
type Teacher struct {
	Person
	Sub string
}

func (p *Person) test() {
	p.name = "ree"
	fmt.Println(p)
}

func (p *Person) Eat(k interface{}) {
	//判断接口是否某个类型
	v, ok := k.(int)
	if !ok {
		fmt.Println("k不是int")
	} else {
		fmt.Println("k的值为", v)
	}

	switch t := k.(type) {
	case int:
		fmt.Println("这个是int", t)
	}
	(*p).name = "jo"
	fmt.Println("方法执行", p.name)

}

func main() {
	/*var f Intef
	//接口赋值需要传指针
	f = &Func{"tom"}
	go f.Add()*/

	/*go func() {
		for {
			fmt.Println("11")
			runtime.Goexit()
		}
	}()*/
	p := Person{name: "tom"}
	p.test()
	nc := make(chan int, 3)
	go consumer(nc)
	go producer(nc)
	time.Sleep(5 * time.Second)
	/*go func() {
		for i := 0; i < 10; i++ {
			nc <- 9999
		}
	}()*/

}
func consumer(in <-chan int) {
	/*for v := range nc {
		fmt.Println("读到的数据", v)
	}*/

	for {

		select {
		case v := <-in:
			fmt.Println("读到的数据", v)
		}
	}

}

func producer(out chan<- int) {

	for i := 0; i < 50; i++ {
		out <- i
		fmt.Println("写出的数据", i)
	}

}
